package org.example.controller;

import org.example.model.User;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    //以前都是返回的统一结果
    @PostMapping("/add")
    public Integer addUser(User user) {
        if(user==null) {
            return null;
        }
        return userService.addUser(user);
    }
    @GetMapping("/query")
    public List<User> queryAll() {
        return userService.queryAll();
    }
    @GetMapping("/{id}")
    public User getUserById(@PathVariable("id") Integer id) {
        return userService.getUserById(id);
    }
    @PutMapping("/{id}")
    public Integer updateUserById(@PathVariable("id") Integer id) {
        return userService.updateById(id);
    }
    @DeleteMapping("/{id")
    public String deleteUserById(@PathVariable("id") Integer id) {
        return userService.deleteUserById(id);
    }
}
